package org.spring.boot.fusion.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServerPropertiesConfig {

	@Autowired
	private ServerProperties serverProperties;

	@Bean
	@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
	public ServerProperties serverProperties() {
		if (serverProperties == null) {
			serverProperties = new ServerProperties();
		}
		System.out.println(serverProperties.getPort());
		int port = (int) ((Math.random() * 9 + 1) * 10000);
		serverProperties.setPort(port);
		return serverProperties;
	}
}
